package com.glc.hms.common.page;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.glc.hms.common.util.HttpContext;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Santa
 * @since 2019/11/27
 */
public class PageFactory {
    /**
     * 获取分页参数
     */
    public static Page defaultPage() {
        HttpServletRequest request = HttpContext.getRequest();

        //每页多少条数据 默认20
        int limit = 20;
        try{
            limit = Integer.valueOf(request.getParameter("limit"));
        }catch (Exception e){}

        //页码 默认1
        int page = 1;
        try{
            page = Integer.valueOf(request.getParameter("page"));
        }catch (Exception e){}

        return new Page(page, limit);
    }

    /**
     * 包装前端返回信息
     */
    public static PageVo createPageInfo(IPage page) {
        PageVo result = new PageVo();
        result.setCount(page.getTotal());
        result.setData(page.getRecords());
        return result;
    }
}























